//
//  ContactUsViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2018/1/8.
//  Copyright © 2018年 企友软mac. All rights reserved.
//

#import "ContactUsViewController.h"
#import "PhoneCell.h"
#import "ContectUsCell.h"
#import "WWebViewController.h"

@interface ContactUsViewController ()<UITableViewDelegate, UITableViewDataSource,ContectUsCellDelegate> {
    UIView *bgView;
    UIView *centerView;
    UIButton *btnCancel;
}

@property (nonatomic, strong)UITableView *tableView;

@end

@implementation ContactUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"联系我们";
    [self.view addSubview:self.tableView];
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.bounces = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];

    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0) {
        return 4;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 50;
    }
    return 100;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HOTCELL"];

    if (indexPath.section == 0){
        if (cell == nil) {
            PhoneCell *phoneCell = [[[NSBundle mainBundle]loadNibNamed:@"PhoneCell" owner:self options:nil]lastObject];
            phoneCell.selectionStyle = UITableViewCellSelectionStyleNone;//去掉cell点击效果

            if (indexPath.row == 0) {
                phoneCell.lbTitle.text = @"全国统一客服热线";
                phoneCell.lbPhone.text = @"95113";
            }else if (indexPath.row == 1) {
                phoneCell.lbTitle.text = @"城北服务监督电话";
                phoneCell.lbPhone.text = @"18636824600";
            }else if (indexPath.row == 2) {
                phoneCell.lbTitle.text = @"城南服务监督电话";
                phoneCell.lbPhone.text = @"18535121905";
            }else if (indexPath.row == 3) {
                phoneCell.lbTitle.text = @"河西服务监督电话";
                phoneCell.lbPhone.text = @"18636824601";
            }
            cell = phoneCell;
        }
    }else if (indexPath.section == 1){
        if (cell == nil) {
            ContectUsCell *contectUsCell = [[[NSBundle mainBundle]loadNibNamed:@"ContectUsCell" owner:self options:nil]lastObject];
            contectUsCell.delegate = self;
            cell = contectUsCell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)delegatBtnClick:(UIButton *)button {

    if (button.tag == 2000) {
        bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT)];
        bgView.backgroundColor = WRGBAColor(0, 0, 0, 0.2);

        centerView = [[UIView alloc] initWithFrame:CGRectMake((WSCREENH_WIDTH - 200) * 0.5, (WSCREENH_HEIGHT - 250) * 0.4 + 50, 200, 250)];
        centerView.backgroundColor = WRGBAColor(255, 255, 255, 1);

        UIImageView *qrImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 180, 180)];
        qrImageView.image = [UIImage imageNamed:@"erweimacode.png"];
        [centerView addSubview:qrImageView];

        UILabel *lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 180, 20)];
        lbTitle.text = @"请使用微信扫描";
        [lbTitle setFont:[UIFont systemFontOfSize:15]];
        lbTitle.textAlignment = NSTextAlignmentCenter;
        [centerView addSubview:lbTitle];
        [centerView addSubview:qrImageView];

        btnCancel = [[UIButton alloc] initWithFrame:CGRectMake((WSCREENH_WIDTH - 40) * 0.5, (WSCREENH_HEIGHT + 250) * 0.5 + 50, 40, 40)];
        [btnCancel setImage:[UIImage imageNamed:@"del_pop.png"] forState:UIControlStateNormal];
        [btnCancel addTarget:self action:@selector(btnCancelClick) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:bgView];
        [self.view addSubview:centerView];
        [self.view addSubview:btnCancel];

    } else if (button.tag == 2001) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"在线客服";
        webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
        [self.navigationController pushViewController:webVc animated:YES];
    } else if (button.tag == 2002) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"服务联系卡";
        webVc.strUrl = [NSString stringWithFormat:@"http://www.sx95113.com/zstapp%@",@"?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhOvPe3N7qFVfUFgbW03cYu9"];
        [self.navigationController pushViewController:webVc animated:YES];
    }
}

- (void)btnCancelClick {
    [bgView removeFromSuperview];
    [centerView removeFromSuperview];
    [btnCancel removeFromSuperview];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [bgView removeFromSuperview];
    [centerView removeFromSuperview];
    [btnCancel removeFromSuperview];
}

@end
